package com.gutsyzhan.bilibili.controller;

import com.gutsyzhan.bilibili.constant.AuthRoleConstant;
import com.gutsyzhan.bilibili.domain.JsonResponse;
import com.gutsyzhan.bilibili.domain.UserMoments;
import com.gutsyzhan.bilibili.domain.annotation.ApiLimitedRole;
import com.gutsyzhan.bilibili.domain.annotation.DataLimitedRole;
import com.gutsyzhan.bilibili.service.UserMomentsService;
import com.gutsyzhan.bilibili.support.UserSupport;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class UserMomentsController {
    @Resource
    private UserMomentsService userMomentsService;

    @Resource
    private UserSupport userSupport;

    /**
     * 新增用户动态
     */
    @ApiLimitedRole(limitedRoleCodeList = {AuthRoleConstant.ROLE_LV0})
    @PostMapping("user-moments")
    @DataLimitedRole
    public JsonResponse<String> addUserMoments(@RequestBody UserMoments userMoments) throws Exception {
        Long userId = userSupport.getCurrentUserId();
        userMoments.setUserId(userId);
        userMomentsService.addUserMoments(userMoments);
        return JsonResponse.success();
    }

    /**
     * 查询订阅动态
     */
    @GetMapping("user-subscribed-moments")
    public JsonResponse<List<UserMoments>> getUserSubscribedMoments(){
        Long userId = userSupport.getCurrentUserId();
        List<UserMoments> userMomentsList = userMomentsService.getUserSubscribedMoments(userId);
        return new JsonResponse<>(userMomentsList);
    }
}
